﻿<Window x:Class="WpfControls.CS.Test.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpf="http://wpfcontrols.com/"
        xmlns:local="clr-namespace:WpfControls.CS.Test"
        xmlns:io="clr-namespace:System.IO;assembly=mscorlib"
        Title="{Binding Path=SelectedItem.(io:FileSystemInfo.FullName), ElementName=Actb}" SizeToContent="WidthAndHeight"
        ResizeMode="NoResize"
        Padding="10"
        FocusManager.FocusedElement="{Binding ElementName=Actb}">
    <Window.Resources>
        <local:FilesystemSuggestionProvider x:Key="FileSystemSuggestionProvider" />
        <local:FileIconConverter x:Key="FileIconConverter" />
        <DataTemplate x:Key="FileInfoTemplate" DataType="io:FileInfo">
            <Border Padding="5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Image Grid.RowSpan="2"
                           Width="32"
                           Height="32"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Source="{Binding Converter={StaticResource FileIconConverter}}"/>
                    <TextBlock Text="{Binding Path=Name}"
                               FontWeight="Bold" 
                               Grid.Column="1" 
                               Grid.Row="0"
                               FontFamily="Segoe UI"
                               VerticalAlignment="Bottom"/>
                    <TextBlock Text="{Binding Path=LastWriteTime, StringFormat='Last Modified: {0}'}"
                               Grid.Column="1"
                               Grid.Row="1"
                               VerticalAlignment="Top"/>
                </Grid>
            </Border>
        </DataTemplate>
        <DataTemplate x:Key="DirectoryInfoTemplate" DataType="io:DirectoryInfo">
            <Border Padding="5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Image Width="32"
                           Height="32"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Source="{Binding Converter={StaticResource FileIconConverter}}"/>
                    <TextBlock Text="{Binding Path=Name}"
                               FontWeight="SemiBold" 
                               Grid.Column="1" 
                               Grid.Row="0"
                               FontFamily="Segoe UI"
                               FontSize="14"
                               VerticalAlignment="Center"/>
                    
                </Grid>
            </Border>
        </DataTemplate>
        <local:CustomTemplateSelector x:Key="CustomTemplateSelector"
                                      FileTemplate="{StaticResource FileInfoTemplate}"
                                      DirectoryTemplate="{StaticResource DirectoryInfoTemplate}"/>
    </Window.Resources>
    <Grid Width="400"
          Margin="20"
          HorizontalAlignment="Center"
          VerticalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Label Content="_Open" />
        <wpf:AutoCompleteTextBox VerticalAlignment="Top"
                                 Height="25"
                                 Grid.Row="0" Grid.Column="1"
                                 DisplayMember="FullName"
                                 ItemTemplateSelector="{StaticResource CustomTemplateSelector}"
                                 Watermark="Search here"
                                 IconPlacement="Left"
                                 IconVisibility="Visible"
                                 Provider="{StaticResource ResourceKey=FileSystemSuggestionProvider}"
                                 x:Name="Actb">
            <wpf:AutoCompleteTextBox.SelectedItem>
                <Binding Path="SelectedPath" Mode="TwoWay">
                    <Binding.ValidationRules>
                        <local:RequiredValidationRule/>
                    </Binding.ValidationRules>
                </Binding>
            </wpf:AutoCompleteTextBox.SelectedItem>
            <wpf:AutoCompleteTextBox.LoadingContent>
                <TextBlock Text="Loading..."
                           Margin="5"
                           FontSize="14" />
            </wpf:AutoCompleteTextBox.LoadingContent>
            <wpf:AutoCompleteTextBox.Icon>
                <Border Width="20"
                        Height="20">
                    <Image Source="Resources/search_icon.png"
                           Height="16"
                           Width="16"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center" />
                </Border>
            </wpf:AutoCompleteTextBox.Icon>
        </wpf:AutoCompleteTextBox>
        <StackPanel Grid.Column="1"
                    Grid.Row="1"
                    Margin="0,10"
                    HorizontalAlignment="Right"
                    Orientation="Horizontal">
            <Button Content="Open"
                    Command="{Binding Path=OpenCommand}"
                    Padding="20,3" />
            <Button Content="Cancel"
                    Margin="5,0"
                    Command="{Binding Path=CancelCommand}"
                    Padding="20,3" />
        </StackPanel>
    </Grid>
</Window>
